<template>
	<view class="deivceGoBack">
		<navBar :title="`${formInfo.lineName}${formInfo.branchLineName ? '(' + formInfo.branchLineName + ')' : ''}`  || ''"></navBar>
		
		<view style="background-color: #FFF;" class="viewBox">
			<view style="padding: 0 20rpx;">
				<!-- #ifdef MP-WEIXIN -->
					<view style="height: 40rpx;background-color: #f5f7fa;"></view>
				<!-- #endif -->
				<view class="text-site">{{formInfo.lineSiteSectionName}}</view>
				<searchCom class="search-input "  v-model="searchText" @enter="determine" @change="searchChange"></searchCom>
			</view>
			<view class="rel_box">
				<u-tabs :list="list1" @click="fnTabClick" :scrollable='false' :lineWidth='90' :activeStyle="{color: '#2F80ED'}"></u-tabs>
			</view>
			<!-- 未派单 -->
			<notDispatch v-if="currIndx === 0" :dataList="notDispatchList" :pmInfo="formInfo"></notDispatch>
			<!-- 已派单 -->
			<alreadyDispatch v-else :dataList="alreadyDispatchList" @refresh="refresh"></alreadyDispatch>
		</view>
		

	</view>
</template>

<script>
	import navBar from "@/components/navBar/navBar.vue"
	import notDispatch from "./components/notDispatch.vue"
	import alreadyDispatch from "./components/alreadyDispatch.vue"
	import searchCom from "@/components/searchCom.vue"
	import {
		diseaseOrderGetList,
		repairOrderRepairList
	} from "@/api/engineeringMaintenance/engineeringMaintenance.js"
	export default {
		name: 'continueToPatrol',
		components: {
			navBar,
			notDispatch,
			alreadyDispatch,
			searchCom
		},
		data() {
			return {
				searchText: undefined,
				formInfo: {},
				list1: [{
					name: '未派单',
					badge: {
						value:0,
						bgColor:'#2F80ED'
					}
				}, {
					name: '已派单',
					badge: {
						value: 0,
						bgColor:''
					}
				}],
				badgeNum: 0,
				currIndx: 0,
				notDispatchList:[],		//未派单列表数据
				alreadyDispatchList:[],	//已派单数据
			}
		},
		onLoad(params) {
			if (params && params.data) {
				this.formInfo = JSON.parse(params.data)	
				console.log(this.formInfo);
			}
		},
		onShow() {
			this.getDataList()
			this.getAlreadyList()
		},
		methods: {
			
			/**
			 * 输入框值变化的时候
			 * @param {String} val
			 */
			searchChange(val) {
				this.searchText = val
				if(!val) {
					this.searchText = undefined
				}
				if(this.currIndx === 0) {
					this.getDataList()
				}else {
					this.getAlreadyList()
				}

			},
			determine(ev) {
				this.keyword = ev
			},
			fnTabClick(val) {
				this.list1.forEach(it =>{
					it.badge.bgColor = ''
				})
				val.badge.bgColor = '#2F80ED'
				this.currIndx = val.index
				console.log(val);
			},
			refresh() {
				this.getDataList()
				this.getAlreadyList()
			},
			getDataList() {
				let resq = {
					currPage: 1,
					pageSize: 10000,
					params: {
						lineId: this.formInfo.lineId,
						lineSiteSectionId: this.formInfo.lineSiteSectionId,
						lineSiteSectionType: this.formInfo.lineSiteSectionType,
						type: 'disease_dispatch',
						pmId:this.formInfo.pmId,
						pmName:this.formInfo.pmName,
						keyword: this.searchText,
						projectId:uni.getStorageSync('isOwner')
					}
				}
				diseaseOrderGetList(resq).then(res => {
					if (res.success) {
						this.$nextTick(() => {
							this.notDispatchList = res.result.list.map(item => ({
								...item,
								isChecked:false
							}))
							// console.log(this.notDispatchList, '-----------')
							this.list1[0].badge.value = res.result.total
						})
					}
				})	
			},
			getAlreadyList() {
				repairOrderRepairList({
					currPage: 1,
					pageSize: 10000,
					params: {
						lineId: this.formInfo.lineId,
						lineSiteSectionId: this.formInfo.lineSiteSectionId,
						lineSiteSectionType: this.formInfo.lineSiteSectionType,
						keyword: this.searchText,
						pmId:this.formInfo.pmId,
						pmName:this.formInfo.pmName,
						projectId:uni.getStorageSync('isOwner'),
						type:"repair"
					}
				}).then(res => {
					console.log(res, '已审核列表')
					if (res.success) {
							this.alreadyDispatchList = res.result.list
							this.list1[1].badge.value = res.result.total
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.deivceGoBack {
		position: relative;
		margin-top: 30rpx;
		background: #F5F7FA;
		.viewBox {
			/* #ifdef MP-WEIXIN */
				padding-top: 160rpx;
			/* #endif */
		}
		.content {
			

			.search-input {
				margin-top: 30rpx !important;
			}
		}

		.rel_box {
			position: relative;

			s .ssj {
				position: absolute;
				left: 228rpx;
				top: 18rpx;
			}

			.xsj {
				position: absolute;
				top: 40rpx;
				left: 228rpx;
			}

		}




	}

	/deep/ .u-badge--error {
		background-color: #9d9595;
	}
	.text-site {
		// background-color: #F5F7FA;
		height: 120rpx;
		font-size: 36rpx;
		font-family: PingFang SC-Bold, PingFang SC;
		font-weight: bold;
		color: #445469;
		line-height: 120rpx;
		padding-left: 20rpx;
	}
</style>
